package com.steven.ourcontest.chat.view

import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.Observer
import com.steven.ourcontest.R
import com.steven.ourcontest.app.AppRouter
import com.steven.ourcontest.base.BaseActivity
import com.steven.ourcontest.chat.adapter.FriendHistoryListAdapter
import com.steven.ourcontest.chat.viewmodel.FriendHistoryViewModel
import kotlinx.android.synthetic.main.activity_chat_friends_history.*

class ChatFriendsHistoryActivity : BaseActivity() {
    private val adapter by lazy {
        FriendHistoryListAdapter(this){
            AppRouter.openUserDetailActivity(this,it)
        }
    }
    private val friendHistoryViewModel:FriendHistoryViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initListener()
    }

    override fun getViewId(): Int? {
        return R.layout.activity_chat_friends_history
    }

    override fun initView() {
        rv_friends?.adapter = adapter
    }

    private fun initListener(){
        friendHistoryViewModel.queryFriendsResponse.observe(this, Observer {
            adapter.listData.clear()
            adapter.listData.addAll(it.data)
            adapter.notifyDataSetChanged()
        })
    }

    override fun onResume() {
        super.onResume()
        friendHistoryViewModel.queryFriends()
    }
}